package com.zzq.tools;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import lombok.Getter;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolUtil {
    @Getter
    private static final ExecutorService executor;

    static {
        // 创建自定义线程池
        executor = new ThreadPoolExecutor(
                5,                          // 核心线程数
                10,                         // 最大线程数
                60L, TimeUnit.SECONDS,      // 空闲线程存活时间
                new LinkedBlockingQueue<>(100),  // 工作队列
                new ThreadFactoryBuilder()  // 线程工厂
                        .setNameFormat("tenderer-check-%d")
                        .build(),
                new ThreadPoolExecutor.CallerRunsPolicy()  // 拒绝策略
        );
    }

}
